home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue37 / DynArr / Array8U.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-07-03  |  1.6 KB  |  74 lines

  1. unit Array8U;
  2.  
  3. interface
  4.  
  5. uses
  6.   WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls,
  7.   Forms, Dialogs, Grids, StdCtrls;
  8.  
  9. type
  10.   TArray8MainForm = class(TForm)
  11.     ListBox1: TListBox;
  12.     btnResizeArray: TButton;
  13.     btnFillArray: TButton;
  14.     procedure FormCreate(Sender: TObject);
  15.     procedure btnResizeArrayClick(Sender: TObject);
  16.     procedure btnFillArrayClick(Sender: TObject);
  17.   private
  18.     MyArray: array of Integer;
  19.     procedure DisplayArray;
  20.   end;
  21.  
  22. var
  23.   Array8MainForm: TArray8MainForm;
  24.  
  25. implementation
  26.  
  27. {$R *.DFM}
  28.  
  29. procedure TArray8MainForm.FormCreate(Sender: TObject);
  30. begin
  31.   SetLength(MyArray, StrToInt(InputBox(
  32.       'Enter your array dimensions',
  33.       'Number of elements:', '10')));
  34.   btnFillArray.Click; { Pretend to push the array filling button }
  35.   DisplayArray
  36. end;
  37.  
  38. procedure TArray8MainForm.btnResizeArrayClick(Sender: TObject);
  39. begin
  40.   SetLength(MyArray, StrToInt(InputBox(
  41.     'Enter your new array dimensions',
  42.     'Number of elements:', '20')));
  43.   DisplayArray
  44. end;
  45.  
  46. procedure TArray8MainForm.btnFillArrayClick(Sender: TObject);
  47. var
  48.   Loop: Integer;
  49. begin
  50.   for Loop := Low(MyArray) to High(MyArray) do
  51.     MyArray[Loop] := Loop;
  52.   DisplayArray
  53. end;
  54.  
  55. procedure TArray8MainForm.DisplayArray;
  56. var
  57.   Loop: Integer;
  58. begin
  59.   with ListBox1, Items do
  60.   begin
  61.     BeginUpdate;
  62.     try
  63.       Clear;
  64.       for Loop := Low(MyArray) to High(MyArray) do
  65.         Add(IntToStr(MyArray[Loop]));
  66.       ItemIndex := High(MyArray)
  67.     finally
  68.       EndUpdate
  69.     end
  70.   end
  71. end;
  72.  
  73. end.
  74.